


/* Test of exclusion restriction */



use  "G:\Data\Workdata\707677\Common\01Data\02STATA\panel_iv_exclusion", clear

cd "G:\Data\Workdata\707677\Common\03Output\01Graphs\03OtherGraphs"




keep if time==1

tab obs_lawyer

egen lawyer_id_unique=group(lawyerid court) // Unique lawyer id within courts. some lawyers work in multiple courts
bys lawyer_id_unique: egen n_lawyer=count(lawyer_id_unique)
egen mean_lawyer_leniency= mean(granted), by(lawyerid court)

gen iv_judge2_all = (mean_lawyer_leniency*n_lawyer - granted)/(n_lawyer-1)

gen iv_lawyer2=iv_judge2_all-(iv_court*obs_court-granted)/(obs_court-1)

sum n_lawyer, d

keep if n_lawyer>=20

egen n_judge=nvals(lawyerid), by(court aar)

sort  court aar lawyerid iv_lawyer n_judge

order court aar lawyerid iv_lawyer n_judge

tab n_judge

keep if n_judge>1

tab court, gen(courtdum)

tab pyear, gen(yeardum)

egen court_pyear =group(court pyear) 
tab court_pyear




/* List of covariates */


local Xvar_short "male age_0_40 age_41_50 age_51_60 age_61_70 erhvervsindk_mean employed_pstill_mean unemployed_pstill_mean legmarried_m1 racedum1 housedum1 passiv_m1 aktiv_m1 higher_secondary university social_mean edu_missing housing_missing timelon_dum1 timelon_dum2 timelon_dum3 timelon_dum4 house_m1"





/* Residualized instrument */



reg iv_lawyer2 i.court_pyear 

predict residualized_lawyer, res

histogram residualized_lawyer




/* Transform instrument so that it is on scale from 0 to 100 (same as dividend) */


replace residualized_lawyer=100*residualized_lawyer




/* Winsorize dividend at 1st and 99th percentile */


sum div_short, detail

winsor div_short, p(0.01) gen(dividend)

sum dividend, detail




/* Plot not winsorized */



#delimit ;


twoway scatter div_short residualized_lawyer, 

xlabel(-40 "-40%" -30 "-30%" -20 "-20%" -10 "-10%" 0 "0%"  10 "10%" 20 "20%" 30 "30%" 40 "40%", nogrid) 

ylabel(0 "0%"  20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%" ) 

graphregion(fcolor(white)) bgcolor(white) scheme(s1color) legend(off)

xtitle("Residualized Trustee Instrument")

ytitle("Dividend") 

;

#delimit cr



graph save exclusion_restriction, replace

graph export exclusion_restriction.pdf, replace






/************************************************/
/*                                              */
/* Regress dividende on residualized instrument */
/*                                              */
/************************************************/



cd G:\Data\Workdata\707677\Common\03Output\02Regresssions



/* Not winsorized - without covariates*/


reghdfe div_short residualized_lawyer, cluster(lawyer_id_unique)


outreg2 using exclusion_restriction.xls, replace ctitle(not_win_no_cov)




/* Not winsorized - with covariates*/


reghdfe div_short residualized_lawyer `Xvar_short', cluster(lawyer_id_unique)

outreg2 using exclusion_restriction.xls, append ctitle(not_win_cov)




/* Winsorized  - without covariates */


reghdfe dividend residualized_lawyer, cluster(lawyer_id_unique)

outreg2 using exclusion_restriction.xls, append ctitle(win_no_cov)




/* Winsorized  - with covariates */


reghdfe dividend residualized_lawyer `Xvar_short', cluster(lawyer_id_unique)

outreg2 using exclusion_restriction.xls, append ctitle(win_cov)












